package com.qk.management.controller;

import com.qk.common.util.PageResult;
import com.qk.common.util.Result;
import com.qk.dto.customer.CustomerDto;
import com.qk.entity.Customer;
import com.qk.management.anno.LogOperation;
import com.qk.management.service.CustomerService;
import com.qk.vo.customer.CustomerVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@Slf4j
@RestController
@RequestMapping("/customers")
public class CustomerController {
    @Autowired
    private CustomerService customerService;
    @GetMapping
    public Result getCustomerList( CustomerDto customerDto) {
        log.info("查询客户");
        PageResult<CustomerVo> pr= customerService.getCustomerList(customerDto);
        return Result.success(pr);
    }
    @PostMapping
    @LogOperation
    public Result addCustomer(@RequestBody Customer customer) {
        log.info("添加客户：{}", customer);
        customerService.addCustomer(customer);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result getCustomerById(@PathVariable Integer id) {
        log.info("查询客户：{}", id);
     CustomerVo customerVO = customerService.getCustomerById(id);
      return Result.success(customerVO);
    }
    @PutMapping
    @LogOperation
    public Result updateCustomer(@RequestBody Customer customer) {
        log.info("更新客户：{}", customer);
        customerService.updateCustomer(customer);
        return Result.success();


    }

}
